package com.didispace.web;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.context.scope.refresh.RefreshScopeRefreshedEvent;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;

import com.didispace.MyBean;
import com.didispace.User;

@Configuration
@RefreshScope
public class TestConfiguration {
	@Value("${from}")
	private String from;
	@Bean
	public User getUser(){
		System.out.println("initial user");
		User user = new User();
		user.setName("hello");
		user.setAge(20);
		return user;
		
	}
	
	@Bean
	@RefreshScope//添加该配置，refresh后，只要在重新调用这个类的时候才会重新注入新的实例
    public MyBean mybean(){
		System.out.println("initial mybean by@Bean mybean()");
    	MyBean mybean = new MyBean();
    	mybean.setTest(from+"eshin");
		return mybean;
    }
}
